package com.qf.springboot.interceptor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class MyInterceptor implements WebMvcConfigurer {
    @Autowired
    private InterceptorConfig interceptorConfig;
    @Autowired
    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        List<String> list = new ArrayList<>();
        list.add("/webjars/**");
        list.add("/assets/**");
        list.add("/login.html");
        list.add("/register.html");
        list.add("/user/login");
        list.add("/user/register");
        list.add("/user/checkUsername");
        list.add("/**");
        registry.addInterceptor(interceptorConfig)
                .addPathPatterns("/**")
                .excludePathPatterns(list);
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/login.html");
    }
}
